<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
/*
	选择商品modal，通过访问此页面选择获取指定商品id
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
	//商品列表
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['num']?:10;
	$return['params']=$params=array('onepluginname'=>'jy_mfuwu');
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	$fields=array('title');
	if($_RQ['find']){
		$field=in_array($_RQ['field'],$fields)?$_RQ['field']:'title';
		$params[$field.' like']='%'.$_RQ['find'].'%';
		$return['params']['find']=$_RQ['find'];
		$return['params']['field']=$field;
	}
	if($_RQ['nomerch']){
		$params['merchid']=0;
		$return['params']['nomerch']=1;
	}
	if($_RQ['noweike']){
		$params['pluginname !=']=array('jy_taobaoke','jy_jdk','jy_pddke');
		$return['params']['noweike']=1;
	}
	if($_RQ['pluginname']){
		$params['pluginname']=$_RQ['pluginname'];
		$return['params']['pluginname']=$_RQ['pluginname'];
	}
	if($_RQ['nopluginname']){
		$params['pluginname']='';
		$return['params']['nopluginname']=$_RQ['nopluginname'];
	}
	if(!$params['pluginname'] && !$_RQ['nopluginname']){
		$params['pluginname !=']=array('jy_taobaoke','jy_jdk','jy_pddke');
	}
	if($_RQ['getinfo']){
		$return['params']['getinfo']=1;
	}
	if($_RQ['isvideo']){
		$params['video <>']='';
		$return['params']['isvideo']=1;
	}
	$list=pdo_getslice('jy_weishop_goods',$params,array($pindex,$psize),$total,array('id','total','image','video','title','merchid','price','originalprice','salenum'),'','id desc');
	if($list){
		foreach($list as &$item){
			$item['originalprice']=$item['originalprice']?:$item['price']*1.2;
			$item['merchtitle']=$item['merchid']>0?'其他商户':'自营平台';
			$item['plugintitle']=pdo_getcolumn('core_plugins',array('name'=>$item['onepluginname']),'title');
			$item['plugintitle']=$item['plugintitle']?'('.$item['plugintitle'].')':'(商城系)';
			if($_RQ['op']=='many' || $_RQ['getinfo']){
				if($_RQ['getinfo']){
					$item['res']=array(
						'title'=>$item['title'],
						'id'=>$item['id'],
						'image'=>tomedia($item['image']),
						'video'=>tomedia($item['video']),
						'price'=>$item['price'],
						'originalprice'=>$item['originalprice'],
						'salenum'=>$item['salenum'],
						'canbuynum'=>1,
						'total'=>$item['total'],
					);
				}else{
					$item['res']=array(
						'title'=>$item['title'],
						'id'=>$item['id'],
						'image'=>tomedia($item['image']),
						'video'=>tomedia($item['video']),
					);
				}
			}else{
				$item['res']=$item['id'];
			}
			
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['htmls']=array(
			'type'=>'list',
			'tabs'=>array(
				array('op'=>'list','title'=>'商品列表'),
			),
			'list'=>array('data'=>'list','del_one'=>false,'delall'=>false,'edit'=>false,'list'=>array(
				array('name'=>'id','title'=>'商品id','type'=>'string'),
				array('type'=>'img_string','title'=>'商品名称_Goods title','img'=>'image',
				'data'=>array(
					array('title'=>'','name'=>'title'),
					array('title'=>'价格：￥','name'=>'price')
					)
				),
				array('type'=>'img_string','title'=>'所属商户/场景体',
				'data'=>array(
					array('title'=>'商户:','name'=>'merchtitle'),
					array('title'=>'场景体:','name'=>'plugintitle')
					)
				),
			),'action'=>array(
				array('type'=>'modal_result','name'=>'res','title_field'=>'title','title'=>'选取'),
			)),
			'search_one'=>array('name'=>'find','select_name'=>'field','select_title'=>'筛选','is_radio'=>true,'options'=>'fields'),
	);
	$return['fields']=array(
		'title'=>'商品名称',
	);
	exi($return);

?>